''' Assignment: Display 3 (Functions & global variables) This program starts as Display2 (at the end of functions, parameters and local variables) Add a global counter and use it in a function ''' from codex import * from time import sleep delay = 1 count = 0 # One function for game play def play_game(message, button, light, delay): global count display.show(message) sleep(delay) pressed = buttons.is_pressed(button) if pressed: pixels.set(light, GREEN) count = count + 1 else: pixels.set(light, RED) print("Count:", count) def ending(count): display.clear() for pix in range(4): pixels.set(pix, BLACK) if count == 4: display.draw_text("You won!", scale=3, x=40, y=100, color=GREEN) col = BLUE elif count == 0: display.draw_text("You lost", scale=3, x=40, y=100, color=RED) else: display.draw_text("Keep trying", scale=3, x=20, y=100, color=BLUE) col = CYAN for pix in range(count): pixels.set(pix, col) # Main Program message = "Hold Button Up" button = BTN_U play_game(message, button, 0, delay) message = "Hold Button Down" button = BTN_D play_game(message, button, 1, delay) message = "Hold Button Left" button = BTN_L play_game(message, button, 2, delay) message = "Hold Button Right" button = BTN_R play_game(message, button, 3, delay) ending(count)